package com.bwie;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * Hello world!
 *
 */
@SpringBootApplication
@EnableAsync
public class rikaolianxi
{
    public static void main( String[] args )
    {
        SpringApplication.run(rikaolianxi.class,args);
        System.out.println( "Hello World!" );
    }
    @Bean("xty")
    public Executor create(){
        ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
        threadPoolTaskExecutor.setCorePoolSize(1); //线程数
        threadPoolTaskExecutor.setMaxPoolSize(1); //最大线程数
        threadPoolTaskExecutor.setQueueCapacity(0); //队列数
        threadPoolTaskExecutor.setKeepAliveSeconds(1000);//线程保持时间
        threadPoolTaskExecutor.setThreadNamePrefix("Async-"); //线程前缀名称
        //线程报错处理
        threadPoolTaskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardPolicy());
        threadPoolTaskExecutor.initialize();//线程初始化
        return threadPoolTaskExecutor;
    }
}
